using System;
using System.Collections.Generic;
using System.Linq;
namespace TemplateWeb.Models.Repositories
{
	#region using
	using TemplateWeb.Helpers;
	using TemplateWeb.Models.ViewModels;
	using TemplateWeb.Models;
	#endregion
	public class ChiTietDonDatHangRepository
	{
		public bool Insert(ChiTietDonDatHang obj)
		{
			try
			{
				DataContext.Instance.ChiTietDonDatHang.AddObject(obj);
				DataContext.Instance.SaveChanges();
				return true;
			}
			catch(Exception ex)
			{
				if(ex.InnerException != null)
					CommonLogging.Logger.Error("ChiTietDonDatHang - Insert: " + ex.InnerException.Message.Replace("\t", string.Empty).Replace("\r", string.Empty).Replace("\n", string.Empty));
				else
					CommonLogging.Logger.Error("ChiTietDonDatHang - Insert: " + ex.Message.Replace("\t", string.Empty).Replace("\r", string.Empty).Replace("\n", string.Empty));
				return false;
			}
		}

		public List<ChiTietDonDatHang> SelectByIDDonDatHang(int iddondathang)
		{
			try
			{
				var lstItem = (from item in DataContext.Instance.ChiTietDonDatHang where item.IDDonDatHang == iddondathang select item).ToList();
				return lstItem;
			}
			catch(Exception ex)
			{
				if(ex.InnerException != null)
					CommonLogging.Logger.Error("ChiTietDonDatHang - SelectByIDDonDatHang: " + ex.InnerException.Message.Replace("\t", string.Empty).Replace("\r", string.Empty).Replace("\n", string.Empty));
				else
					CommonLogging.Logger.Error("ChiTietDonDatHang - SelectByIDDonDatHang: " + ex.Message.Replace("\t", string.Empty).Replace("\r", string.Empty).Replace("\n", string.Empty));
				return new List<ChiTietDonDatHang>();
			}
		}
	}
}